/**
 * xmlconnector.h is part of cbs-framework.
 *
 * cbs-framework is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * cbs-framework is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with cbs-framework.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef XMLCONNECTOR_H
#define XMLCONNECTOR_H

#include "connector.h"
#include <string>
#include <QXmlStreamReader>

class XmlConnector : public Connector
{
public:

    virtual ~XmlConnector() {}

    virtual bool Load();

protected:

    virtual void ReadElement( QXmlStreamReader::TokenType a_type, QXmlStreamReader & a_xmlStream ) = 0;

    virtual void HandleError( QXmlStreamReader & a_xmlStream ) = 0;

    // Constructor only visible by subclasses.
    XmlConnector( const std::string & a_file );

    const std::string & File();

    const QXmlStreamReader & XmlStream();

    bool IsStartElement( QXmlStreamReader::TokenType a_type );
    bool IsEndElement( QXmlStreamReader::TokenType a_type );

private:

    // Fields.
    // -------

    std::string m_file;

    QXmlStreamReader m_xmlStream;

    // Methods.
    // --------

    // Protect default constructor.
    XmlConnector();

    // Protect copy constructor.
    XmlConnector( const XmlConnector & a_other );

    // Protect operator =.
    XmlConnector & operator = ( const XmlConnector & a_other );
};

#endif // XMLCONNECTOR_H
